package com.cow.sram.module.distribution;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cow.framework.core.base.BaseComponent;
import com.cow.sram.data.dao.RoleresourceDAO;
import com.cow.sram.data.entity.Resourceinfo;
import com.cow.sram.data.entity.Roleresource;
import com.cow.sram.data.mapper.ResourceinfoMapper;
import com.cow.sram.data.mapper.RoleresourceMapper;
/**
 * 角色资源
 * @author Administrator
 *
 */
@Service
public class RoleResourceService extends BaseComponent{
	  	 @Autowired
	  	RoleresourceDAO roleResourceDao;
	  	@Autowired
	  	ResourceinfoMapper resourceinfoMapper;
	  	@Autowired 
	  	RoleresourceMapper roleresourceMapper;
	     
	     /**查带ID*/
	     public Roleresource getRoleresourceById(Integer id){
	    	 return roleResourceDao.findOne(id);
	     }
	     
	     /**增*/
	     public Roleresource newRoleresource(Roleresource ur){
	    	 return roleResourceDao.save(ur);
	     }
	     
	     /**删*/
	     public void delRoleresource(Integer id){
	    	 roleResourceDao.delete(id);
	     }
	     /**根据roleId删除*/
	     public void delroleId(Integer roleId){
	    	 roleresourceMapper.delRoleId(roleId);
	     }
	     
	     /**根据resourceId删除*/
	     public void delByResourceId(Integer resourceId){
	    	 Roleresource roleresource=this.getRoleresourceById(resourceId);
	    	 roleresourceMapper.delByResourceId(resourceId);
	     }
	     
	    public void delRoleResourceByroleId(Integer roleid,String resourcetype,String systemid){
	    	roleResourceDao.delRoleResourceByroleId(roleid, resourcetype, systemid);
	     }
	     /**角色资源查找*/
	  	public List<Resourceinfo> findRoleResource(Map parmMap){
	  		return resourceinfoMapper.queryRoleResource(parmMap);
	  	}
	  	
	    /**根据用户查找资源*/
	  	public List<Resourceinfo> findUserResource(Map parmMap){
	  		return resourceinfoMapper.queryUserResource(parmMap);
	  	}
	     
	     /**判断角色是否存在资源权限*/
	     public boolean isExist(Integer roleId,Integer resourceId){
	    	 List list = roleResourceDao.findByRoleidAndResourceid(roleId, resourceId);
	    	 if(list != null && list.size() > 0){
	    		 return true;
	    	 }else{
	    		 return false;
	    	 }
	     }
}
